from pathlib import Path
from shutil import copyfile

import addict
import tomli


class Configer:
    def __init__(self, cfg_file) -> None:
        self.cfg_file = Path(cfg_file)
        self.params = self._decode_config_file()

    def snapshot(self, save_dir):
        copyfile(self.cfg_file, Path(save_dir) / self.cfg_file.name)
        return

    def _decode_config_file(self):
        # TODO<CL>: 配置文件可能存在引用
        with self.cfg_file.open("rb") as f:
            return addict.Dict(tomli.load(f))
